package com.black.web.app.store;

import com.black.app.domain.req.store.add.AppStoreFreightTemplateAddReq;
import com.black.app.domain.req.store.edit.AppStoreFreightTemplateEditReq;
import com.black.app.domain.req.store.query.AppStoreFreightTemplateQueryReq;
import com.black.app.domain.resp.store.AppStoreFreightTemplateResp;
import com.black.app.service.store.AppStoreFreightTemplateService;
import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "app-运费模板相关Api")
@RestController
@RequestMapping("/app/freightTemplate")
public class AppStoreFreightTemplateController extends BaseController {

    @Autowired
    private AppStoreFreightTemplateService appStoreFreightTemplateService;

    @ApiOperation(value = "分页查询运费模板")
    @GetMapping("/list")
    public R<PageInfo<AppStoreFreightTemplateResp>> paginationQuery(AppStoreFreightTemplateQueryReq req) {
        PageInfo<AppStoreFreightTemplateResp> page = this.appStoreFreightTemplateService.paginationQuery(req);
        return R.ok(page);
    }

    @ApiOperation(value = "新增运费模板")
    @PostMapping
    public R add(@RequestBody @Valid AppStoreFreightTemplateAddReq req) {
        boolean result = this.appStoreFreightTemplateService.add(req);
        return super.isSuccess(result);
    }

    @ApiOperation(value = "根据templateId查询运费模板")
    @GetMapping(value = "/{templateId}")
    public R<AppStoreFreightTemplateResp> findByTemplateId(@PathVariable(value = "templateId") Integer templateId) {
        return R.ok(this.appStoreFreightTemplateService.findByTemplateId(templateId));
    }


    @ApiOperation(value = "修改运费模板")
    @PutMapping
    public R edit(@RequestBody @Valid AppStoreFreightTemplateEditReq req) {
        boolean result = this.appStoreFreightTemplateService.edit(req);
        return super.isSuccess(result);
    }

    @ApiOperation(value = "删除运费模板")
    @DeleteMapping("/{ids}")
    public R deleteById(@PathVariable(value = "ids") Integer[] ids) {
        boolean result = this.appStoreFreightTemplateService.deleteById(ids);
        return super.isSuccess(result);
    }
}
